Skip to content

GFM: add https:// scheme to www auto-links - #798

Open
RaphaelFakhri wants to merge 2 commits into
typelevel:mainfrom
RaphaelFakhri:fix/gfm-www-autolink-scheme
Open

RaphaelFakhri wants to merge 2 commits into
typelevel:mainfrom
RaphaelFakhri:fix/gfm-www-autolink-scheme

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Nov 3, 2026 •

Copy link
Copy Markdown

With the GitHubFlavor extension, www.link.com was parsed into SpanLink.external("www.link.com") and rendered as <a href="www.link.com">. Browsers resolve that as a relative path, so the link does not reach the external site.

This change prefixes https:// to the link target in AutoLinkParsers, in the same place where email auto-links already get mailto:. The link text stays www.link.com. The GFM spec (section 6.9, "Autolinks (extension)") inserts http. This change uses https instead because most sites serve HTTPS, and a bare www. link gives no way to know the site's scheme. A protocol-relative //www.link.com is not used because EPUB, PDF, and file:// output have no page scheme for it to inherit.

The www parser is only used by GitHubFlavor. reStructuredText standalone links are not affected.

Tests

  • Updated the two www auto-link tests in GitHubFlavorSpec to expect the https:// target.
  • GitHubFlavorSpec passes on Scala 2.12 and 3.3.6 (44 tests), and core/test passes on Scala 3.3.6. scalafmtCheck and Test/scalafmtCheck are clean.

Fixes #797

@RaphaelFakhri

Copy link
Copy Markdown
Author

The Validate Steward Config failure is unrelated to this change. The job ran scala-steward on Java 11, and scala-steward now needs Java 17 (UnsupportedClassVersionError, class file version 61.0). Main already runs that job on temurin@17, so the branch is now rebased onto main.

@RaphaelFakhri
RaphaelFakhri force-pushed the fix/gfm-www-autolink-scheme branch from 760cc10 to c1ed060 Compare November 6, 2026 20:19
@Koroeskohr

Copy link
Copy Markdown
Contributor

Problem with prepending http:// is you don't actually know the protocol used. If anything, the default should be https://. I remember browsers interpreting //www.example.com as an absolute URL, that is also worth looking into

@RaphaelFakhri RaphaelFakhri changed the title GFM: add http:// scheme to www auto-links GFM: add https:// scheme to www auto-links Nov 15, 2026
@RaphaelFakhri

Copy link
Copy Markdown
Author

Agreed, https:// is the better default. 1e139e7 switches the inserted scheme to https://, and the two www tests now expect it.

Browsers do treat //www.example.com as an absolute, protocol-relative URL. It takes the scheme of the page it appears on. That works for HTML served over HTTP or HTTPS. Laika also renders EPUB and PDF, and HTML is often opened from disk. There, //www.example.com resolves against file: or has no base scheme, so the link breaks again. A fixed https:// works in every output format. The one case it gets wrong is a site that serves only plain HTTP.

GitHubFlavorSpec passes on Scala 2.12 and 3.3.6, and core/test passes on 3.3.6. With the parser still inserting http://, the two updated tests fail. The PR title and description are updated to match.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHubFlavor: www auto-links render without a scheme and resolve as relative links

2 participants